package com.woniu.gf.pawn.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

/**
 * @BelongsProject: spring-cloud
 *  * @BelongsPackage: com.woniu.cq.gateway.filter
 *  * @Author: wu wei
 *  * @CreateTime: 2020-09-22 14:27
 *  * @Description:
 */
@Component
public class MyFilterGatewayFilterFactory extends AbstractGatewayFilterFactory<MyFilterGatewayFilterFactory.MyConfig> {

    public MyFilterGatewayFilterFactory(){
        super(MyConfig.class);
    }
    public List<String> shortcutFieldOrder() {
        return Arrays.asList("name");
    }
    public static class MyConfig{
        private String name;
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
    }
    @Override
    public GatewayFilter apply(MyConfig config) {
        return new GatewayFilter() {
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                System.out.println(config.getName());
                return chain.filter(exchange);
            }
        };
    }
}
